package com.sharding.test.web;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sharding.test.dto.RPage;
import com.sharding.test.dto.TsUserDto;
import com.sharding.test.entity.TsUser;
import com.sharding.test.service.TsUserService;
import com.sharding.test.utils.MapUtil;

import lombok.extern.slf4j.Slf4j;


@Slf4j
@RestController
@RequestMapping("/tsuser")
public class TsUserController {

	@Resource
	private TsUserService userService;
	
	
	@GetMapping("/get/{id}")
	public TsUser  getUser(@PathVariable("id")Long id) {
		TsUser user = userService.getById(id);
		return user;
	}
	
	@GetMapping("/create")
	public boolean create(TsUser user) {
		return userService.create(user);
	}
	 
	@GetMapping("/list")
	public RPage<TsUserDto> getUserList(UserQueryRequest request){
		//if(log.isDebugEnabled()) {
			log.info(""+request);
		//}
		Map<String, Object> params=null;
		try {
			params = MapUtil.objectToMap(request);
		} catch (Exception e) {
			e.printStackTrace();
		}

		RPage<TsUserDto> page = userService.getUserPage(params);
		if(page!=null) {
			return page;
		}
		return null;
	}
}
